import 'package:crawler/widgets/scaffold_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';
import 'package:crawler/global/color.dart';

import 'player_cont.dart';

class PlayerPage extends GetView<PlayerCont> {
  const PlayerPage({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ScaffoldBar(
      title: '画板',
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          InAppWebView(
              initialSettings: controller.settings,
              shouldOverrideUrlLoading: (controller, navigationAction) async {
                return NavigationActionPolicy.ALLOW;
              },
              onWebViewCreated: (InAppWebViewController webViewController) {
                controller.controller = webViewController;
                controller.loadPage();
                controller.setJavaScriptHandler(context);
              }
          ),
          Positioned(
              bottom: Get.height * 0.08,
              child: Container(
                  decoration: BoxDecoration(
                    color: LWColor.toolBarBGColor,
                    borderRadius: BorderRadius.circular(10.0)
                  ),
                  width: Get.width * 0.9,
                  padding: const EdgeInsets.all(5),
                  child: Obx(() => Row(
                    children: [
                      IconButton(onPressed: controller.playBtnOnClick, icon: Icon(controller.isPlaying ? Icons.pause : Icons.play_arrow)),
                      Text(controller.reduceText(controller.positionText)),
                      const Padding(padding: EdgeInsets.symmetric(horizontal: 5), child: Text('/')),
                      Text(controller.reduceText(controller.durationText)),
                      Expanded(child: Slider(value: controller.sliderValue, onChanged: controller.sliderOnChange)),
                      DropdownButton<String>(
                        value: controller.selectedValue,
                        onChanged: (String? newValue) {

                        },
                        items: controller.items.map((String item) {
                          return DropdownMenuItem<String>(
                            value: item,
                            child: Text(item),
                          );
                        }).toList(),
                      )
                    ],
                  ))
              )
          )
        ],
      )
    );
  }
}